<?php
namespace app\shell;

use app\model\AdminPathinfoAccountModel;
use app\service\AdminPathinfoService;
use app\service\UserService;
use share\console\CConsole;
use share\console\CLIRunner;
use share\exception\ApiException;
use share\service\IdMakerService;
use share\service\MQService;
use share\service\UserBaseService;
use share\utils\Helper;

class CUserInfo extends CLIRunner{

    /**
     * 重置密码
     */
    public function reset_pass_action(){     
        $id = CConsole::prompt("input user id to reset",1);        
        $pass = substr(Helper::getUnique(),0,8);
        CConsole::print_line("reset the user pass. new pass is   ".$pass);
    }

    public function redo_nick_name_action(){
        $userInfo = UserBaseService::getAllByFilter(['nick_name' => '']);
        foreach($userInfo as $user){
            if(!empty($user['phone'])){
                $nickName = $user['phone'];
            }
            else if(!empty($user['email'])){
                $nickName = $user['email'];
            }
            else{
                $nickName ="no name";
            }
            $tn = time();
            $update = [
                'nick_name' => $nickName,
                'modifytime' => $tn,
            ];
            UserBaseService::update($user['user_id'], $update);
        }
        return count($userInfo);
    }

    public static function test_add_full_action(){        
        $id = IdMakerService::make(IdMakerService::NAME_OF_USER_BASE);
        $account = '110'.date("mdHis");
        $userBase = [
            'id'  => $id,
            "user_id" => Helper::getUnique(),
            "token" => Helper::getUnique(),
            "status" => UserBaseService::USER_STATE_OF_NORMAL,
            "vendor" => 'ENZ',
            "identity_id" => "",
            'phone' => $account,
        ];
        $userDetail = [
            'id'  => $id,
            "phone_code" => '86',              
            "location" => 'CN', 
            "server_site" => "",
            "nick_name" => $account,
        ];
        var_dump($userBase, $userDetail);
        $ret = UserBaseService::addFullUser($userBase,$userDetail);
        if(!$ret){
            var_dump("add failed");
        }
    }
}